我有一个多模块maven项目,我创建了一个新的模块,依赖于其他3个模块.(我已经有一个生成.war文件的web app maven模块,现在我需要这个)
该模块的输出是.jar,它还有一些资源:
现在我想生成一个生产就绪文件夹,以便我可以将其上传到我的服务器.我希望maven可以为我做这件事.
我需要以下布局:
myjar.jar
/libs/ (the 3 other maven modules that are dependancies)
/resources
Run Code Online (Sandbox Code Playgroud)
此外,还有一些通用的依赖项,我的父pom.xml就像slf4j/log4j /我也需要打包.
如果我可以添加一个开关到mvn会产生这样的效果会很酷:
mvn clean install production
Run Code Online (Sandbox Code Playgroud)
我打算通过命令行在我的服务器上运行它.
原始代码如下所示:
module Acme
class Address
STREET_NAME = "123 acme inc drive".freeze
..
..
end
end
Run Code Online (Sandbox Code Playgroud)
这是第三方宝石,我希望我能STREET_NAME以某种方式修改初始化程序中的变量,而无需编辑源代码.这可能吗?
我的spring MVC和hibernate应用程序有一个多maven模块.
我的布局如下:
/myapp-web
/myapp-web/src/main/java
/myapp-web/src/main/webapp
/myapp-web/src/main/webapp/web-inf
/myapp-web/src/main/webapp/web-inf/web.xml
/myapp-web/src/main/webapp/web-inf/web-context.xml (spring wiring code etc)
/myapp-web/src/main/webapp/web-inf/config/hibernate.cfg.xml
/myapp-web/src/main/webapp/assets/... (folder for css, javascript, images)
/myapp-web/src/main/webapp/views (folders with freemarker .ftl files)
Run Code Online (Sandbox Code Playgroud)
我的pom.xml:
..
<packaging>war</packaging>
..
<dependency>
<artifactId>jetty-server</artifactId>
<groupId>org.eclipse.jetty</groupId>
<version>${jetty-version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty-version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty-version}</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我有另一个嵌入式码头的例子,我成功设置了,我可以运行.我甚至设置了一个启动/停止脚本,因此它适用于Ubuntu.这不是一个spring mvc应用程序,所以它更容易,因为它没有web.xml文件等. 我创建了一个/assembly/assembly.xml文件,我是否还需要为spring mvc应用程序执行此操作?
然后我将其添加到我的pom.xml插件部分:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin}</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
<!-- jar plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin}</version>
<configuration>
<archive>
</archive>
</configuration>
</plugin>
<!-- jetty plugin -->
<plugin>
<!-- This …Run Code Online (Sandbox Code Playgroud) 我有一个/ scripts文件夹,其中包含我项目的一些ruby脚本.
/scripts
/scripts/app/models.rb
/scripts/config/config.yml
/scripts/lib
/scripts/lib/myapp/test.rb
Run Code Online (Sandbox Code Playgroud)
在我的test.rb中,我有以下代码正确加载config.yml文件:
env = ENV['ENV'] || 'development'
config = YAML::load(File.open('config/config.yml'))[env]
Run Code Online (Sandbox Code Playgroud)
现在位于test.rb文件的顶部,我正在尝试加载我使用ActiveRecord的models.rb文件,但是我收到错误:
require File.join(File.dirname(__FILE__), "../../", 'models')
Run Code Online (Sandbox Code Playgroud)
错误:
1.9.1/rubygems/custom_require.rb:36:在`require':无法加载这样的文件 - lib/myapp /../../ models(LoadError)
我试过了:
require 'app/models'
Run Code Online (Sandbox Code Playgroud)
这也没用.
我做错了什么,为什么config.yml文件正确加载?
我正在使用slick 2.0.1(如果需要可以升级),我想从数据库中检索自动递增值(postgresql).
我已经在这方面看到了一些关于SO的问题,但它们相当陈旧,我希望有一个更好的方法,而不是做这个答案所暗示的:Scala&Play!&Slick&PostgreSQL自动增量
def autoInc = name ~ price ~ description returning id
def add(product: Product)(implicit s:Session): Long = {
Products.autoInc.insert(p.name, p.price, p.description)
}
Run Code Online (Sandbox Code Playgroud)
你必须在autoInc方法中重新输入模型的字段,这是重复我希望避免的事情.
有没有更好的方法,或者我应该这样做?
我选择的方法是让我的模型poso(普通的旧scala对象):
case class Product(.....)
Run Code Online (Sandbox Code Playgroud)
然后我的dao类看起来像:
class ProductDao extends ProductDao {
class Products(tag: Tag) extends Table[Product](tag, "products") {
def id = ...
def name = ..
def * = (id, name) <> (Product.tupled, Product.unapply)
}
val products = TableQuery()
}
Run Code Online (Sandbox Code Playgroud)
另外作为旁注,对于*方法,我是否必须输入所有类似的属性,还是有更好的方法呢?
我有一个非常新的rails 4.1.1项目设置,我添加了rspec并运行了生成器等.
到目前为止,我已经添加了1个控制器和2个模型.
我的gemfile.lock有这个:
rspec-core (3.0.2)
rspec-support (~> 3.0.0)
rspec-expectations (3.0.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.0.0)
rspec-mocks (3.0.2)
rspec-support (~> 3.0.0)
rspec-rails (3.0.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
rspec-mocks (~> 3.0.0)
rspec-support (~> 3.0.0)
rspec-support (3.0.2)
Run Code Online (Sandbox Code Playgroud)
现在,当我运行rspec时,我得到了这个输出:
/Users/me/.rvm/gems/ruby-2.1.1@testapp1/gems/sass-3.2.19/lib/sass/version.rb:5: warning: loading in progress, circular require considered harmful - /Users/me/.rvm/gems/ruby-2.1.1@testapp1/gems/sass-3.2.19/lib/sass.rb
from /Users/me/.rvm/gems/ruby-2.1.1@testapp1/bin/ruby_executable_hooks:15:in `<main>'
from /Users/me/.rvm/gems/ruby-2.1.1@testapp1/bin/ruby_executable_hooks:15:in `eval'
from /Users/me/.rvm/gems/ruby-2.1.1@testapp1/bin/rspec:23:in `<main>'
from /Users/me/.rvm/gems/ruby-2.1.1@testapp1/bin/rspec:23:in `load'
from /Users/me/.rvm/gems/ruby-2.1.1@testapp1/gems/rspec-core-3.0.2/exe/rspec:4:in `<top (required)>'
from /Users/me/.rvm/gems/ruby-2.1.1@testapp1/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:38:in `invoke' …Run Code Online (Sandbox Code Playgroud) 在我的播放应用程序中,我正在您通常在代码中进行日志记录(跟踪,调试,错误等).
对于那些我没有抓到的错误,我可以在哪里放置日志记录,以便缓存我错过的错误?是否有一个中心事件,我可以挂钩,将捕获所有错误?
另外,每当我的应用程序中出现错误时,我应该如何显示友好的错误页面?(以及如何在开发中显示错误,以及生产环境中的自定义错误页面)
我的表格如下:
case class PasswordData(currentPassword:String,newPassword:String,verifyPassword:String)
val passwordForm = Form(
mapping(
)(PasswordData.apply)(PasswordData.unapply) verifying("Passwords do not match", fields => fields match {
case data => (data.newPassword == data.verifyPassword)
})
)
Run Code Online (Sandbox Code Playgroud)
我的控制器操作遵循通常的模式:
passwordForm.bindFromRequest.fold(
error => {},
form => {}
)
Run Code Online (Sandbox Code Playgroud)
我现在遇到的问题是我需要验证输入的'currentPassword'是否与用户对象上的相同.
userDao.getById(userId).password == form.currentPassword
Run Code Online (Sandbox Code Playgroud)
但我不能这样做,因为我不知道如何将userId传递给我的表单定义,因为它是动态的.
即我不能这样做:
"currentPassword" -> nonEmptyText.verifying(....) // userId not in scope
Run Code Online (Sandbox Code Playgroud)
更新
我也尝试使用它们显示这些错误(它们当前不显示错误,我只看到ul标签).
@if(form.hasGlobalErrors) {
<ul>
@form.errors.foreach { error =>
<li>@error.message</li>
}
</ul>
}
Run Code Online (Sandbox Code Playgroud) 我试图使用pip安装一些东西,并且我不断收到此UserWarning错误(见下文).
我试图升级pip,你可以看到下面的错误.
我有一段时间没有在我的系统上使用python,它似乎被打破了.会是什么呢?
pip install -U pip
/usr/local/bin/pip:5: UserWarning: Module _markerlib was already imported from /Library/Python/2.7/site-packages/distribute-0.6.49-py2.7.egg/_markerlib/__init__.pyc, but /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python is being added to sys.path
from pkg_resources import load_entry_point
Downloading/unpacking pip from https://pypi.python.org/packages/py2.py3/p/pip/pip-7.1.2-py2.py3-none-any.whl#md5=5ff9fec0be479e4e36df467556deed4d
Downloading pip-7.1.2-py2.py3-none-any.whl (1.1MB): 1.1MB downloaded
Installing collected packages: pip
Found existing installation: pip 1.5.6
Uninstalling pip:
Cleaning up...
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 283, in run
requirement_set.install(install_options, global_options, root=options.root_path)
File "/Library/Python/2.7/site-packages/pip/req.py", line 1431, in install …Run Code Online (Sandbox Code Playgroud) 我在/ views/layouts中有3个布局,用于我网站的3个不同部分.
我的资产看起来像:
/javascripts/layout1/*.js
/javascripts/layout2/*.js
/javascripts/layout3/*.js
/stylesheets/layout1/*.css
/stylesheets/layout2/*.css
/stylesheets/layout3/*.css
Run Code Online (Sandbox Code Playgroud)
现在在一个特定的布局中,比如layout1,我怎么才能只为这个布局包含样式/ javascript文件?